<?php

namespace app\api\controller;

use app\common\controller\Api;

use think\Db;

/**
 * 砍价接口
 */
class CutdownFollow extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\CutdownFollow();

    }

    /**
     * 查看
     */
    public function index()
    {
        $this->limitFields = 'id,cutdown_id,goods_id,deal_price,item_id,createtime';
        list($where, $sort, $order, $offset, $limit, $field) = $this->buildparams();

        $total = $this->model
            ->where($where)
            ->order($sort, $order)
            ->count();

        $list = $this->model
            ->field($field)
            ->where($where)
            ->order($sort, $order)
            ->limit($offset, $limit)
            ->select();

        foreach ($list as $k => $v) {
            $cutdown = $v->cutdown;
            $goods_image = Db::name('goods')->where(['id' => $v->cutdown->goods_id])->value('image');
            $list[$k]['goods_image'] = $goods_image;
        }

        $result = array("total" => $total, "rows" => $list);
        $this->success('', $result);
    }







}